package JavaCode;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Kechelle
 * @Date 2020/9/12 16:35
 * @Version 1.0
 */
public class StringContain {
    public static boolean function(String str1,String str2){
        char[] charsA = str1.toCharArray();
        char[] charsB = str2.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        for (int i=0;i<str1.length();i++){
            if (map.get(charsA[i]) == null){
                map.put(charsA[i],1);
            }else {
                map.put(charsA[i], map.get(charsA[i]) + 1);
            }
        }
        //遍历判断b串
        for (int i=0;i<str2.length();i++){
            if (map.get(charsB[i]) == null){
                return false;
            }else {
                map.put(charsB[i], map.get(charsB[i]) - 1);
                if (map.get(charsB[i]) < 0){
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String str1 = "abccd";
        String str2 = "bd";
        System.out.println(StringContain.function(str1,str2));
    }
}
